package com.epam.tcs.dao.hibernate.entities;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Where;

import java.io.Serializable;
import java.util.List;

@Entity
@Table(name = "tcs_theme")
public class Theme implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1898806101795096802L;
	/**
	 * 
	 */
	private Long theme_id;
	private String name;
	private String description;
	private int hours;

	private List<Program> programs;
	private List<ThemeItem> lectures;
	private List<ThemeItem> practices;

	public Theme() {
	}

	public Theme(String name, String description, int hours,
			List<Program> programs, List<ThemeItem> lectures,
			List<ThemeItem> practices) {
		this.name = name;
		this.description = description;
		this.hours = hours;
		this.programs = programs;
		this.lectures = lectures;
		this.practices = practices;
	}

	@Id
	@Column(name = "theme_id", length = 4)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getTheme_id() {
		return theme_id;
	}

	public void setTheme_id(Long theme_id) {
		this.theme_id = theme_id;
	}

	@Column(name = "name", length = 40)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "description")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "hours", length = 4)
	public int getHours() {
		return hours;
	}

	public void setHours(int hours) {
		this.hours = hours;
	}

	// many to many with tcs_program
	// @ManyToMany(fetch = FetchType.EAGER, mappedBy = "themes")
	@ManyToMany(fetch = FetchType.LAZY, mappedBy = "themes")
	public List<Program> getPrograms() {
		return programs;
	}

	public void setPrograms(List<Program> programs) {
		this.programs = programs;
	}

	// one to many with tcs_lecture

	// @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy ="theme")
	@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}, mappedBy = "theme")
	@Where(clause="type=0")
	public List<ThemeItem> getLectures() {
		return lectures;
	}

	public void setLectures(List<ThemeItem> lectures) {
		this.lectures = lectures;
	}

	// one to many with tcs_practices
	// @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy ="theme")
	@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}, mappedBy = "theme")
	@Where(clause="type=1")
	public List<ThemeItem> getPractices() {
		return practices;
	}

	public void setPractices(List<ThemeItem> practices) {
		this.practices = practices;
	}

}
